package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@HttpInlet(Conn.INLET_GET_INS_CHECK)
public class GetInsSelect extends JTAsyGet<GetInsSelect.Info> {

    public String token = JTApplication.jtPreferences.readToken();

    public String userId = JTApplication.jtPreferences.readUserID();

    public String orderId = "";

    public GetInsSelect(AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        JSONObject body = apiTYF.optJSONObject("body");

        JSONArray detailList = body.optJSONArray("orderDetailList");

        if (detailList != null) {

            for (int i = 0; i < detailList.length(); i++) {

                JSONObject object_vci = detailList.optJSONObject(i);

                InsItem mItem = new InsItem();

                mItem.name = object_vci.optString("bname");

                mItem.type = object_vci.optString("insurance_type");

                mItem.num = object_vci.optString("num");

                mItem.flag = object_vci.optString("flag");

                mItem.baoe = object_vci.optString("baoe");

                mItem.price = object_vci.optString("price");

                info.insList.add(mItem);

            }
        }


        return info;
    }

    public static class Info implements Serializable {

        public String msg;

        public List<InsItem> insList = new ArrayList<>();

    }

    public static class InsItem implements Serializable {

        public String name, type, num, flag, baoe, price;

    }


}
